﻿using WikiPlex.Contrib.Console;
using Xunit;
using Xunit.Extensions;

namespace WikiPlex.Contrib.Facts.Console
{
    public class ArgumentsFacts
    {
        [Fact]
        public void ShouldIndicateHelpIsDisplayedIfMissingArguments()
        {
            Arguments arguments = Arguments.Parse(new string[0]);

            Assert.True(arguments.DisplayHelp);
        }

        [Fact]
        public void ShouldIndicateHelpIsDisplayedIfFirstArgIsQuestionMark()
        {
            Arguments arguments = Arguments.Parse(new[] {"/?"});

            Assert.True(arguments.DisplayHelp);
        }

        [Fact]
        public void ShouldIndicateHelpIsDisplayedIfArgsLengthNotTwo()
        {
            Arguments arguments = Arguments.Parse(new[] {"foo"});

            Assert.True(arguments.DisplayHelp);
        }

        [Fact]
        public void ShouldIndicateHelpIsDisplayedIfSourceArgIsCommandPrefixed()
        {
            Arguments arguments = Arguments.Parse(new[] {"/s:something", "output"});

            Assert.True(arguments.DisplayHelp);
        }

        [Fact]
        public void ShouldIndicateHelpIsDisplayedIfOutputArgIsCommandPrefixed()
        {
            Arguments arguments = Arguments.Parse(new[] {"source", "/s:something"});

            Assert.True(arguments.DisplayHelp);
        }

        [Theory]
        [InlineData("source", "output")]
        [InlineData("'source'", "'output'")]
        [InlineData("\"source\"", "\"output\"")]
        public void ShouldSetSourceAndOutputFolder(string source, string output)
        {
            Arguments arguments = Arguments.Parse(new[] {source, output});

            Assert.Equal("source", arguments.SourceFolder);
            Assert.Equal("output", arguments.OutputFolder);
        }

        [Theory]
        [InlineData("/p=*.foo")]
        [InlineData("/p:*.foo")]
        [InlineData("/p='*.foo'")]
        [InlineData("/p=\"*.foo\"")]
        [InlineData("/p:'*.foo'")]
        [InlineData("/p:\"*.foo\"")]
        [InlineData("/pattern=*.foo")]
        [InlineData("/pattern:*.foo")]
        [InlineData("/pattern='*.foo'")]
        [InlineData("/pattern=\"*.foo\"")]
        [InlineData("/pattern:'*.foo'")]
        [InlineData("/pattern:\"*.foo\"")]
        public void ShouldSetTheSourceFilePattern(string argument)
        {
            Arguments arguments = Arguments.Parse(new[] {argument, "src", "dest"});

            Assert.Equal("*.foo", arguments.SourceFilePattern);
        }

        [Theory]
        [InlineData("/t=foo.master")]
        [InlineData("/t:foo.master")]
        [InlineData("/t='foo.master'")]
        [InlineData("/t=\"foo.master\"")]
        [InlineData("/t:'foo.master'")]
        [InlineData("/t:\"foo.master\"")]
        [InlineData("/template=foo.master")]
        [InlineData("/template:foo.master")]
        [InlineData("/template='foo.master'")]
        [InlineData("/template=\"foo.master\"")]
        [InlineData("/template:'foo.master'")]
        [InlineData("/template:\"foo.master\"")]
        public void ShouldSetTheTemplateLocation(string argument)
        {
            Arguments arguments = Arguments.Parse(new[] {argument, "src", "dest"});

            Assert.Equal("foo.master", arguments.TemplateLocation);
        }
    }
}